//
//  AY_VpUseCell.m
//  AiYue
//
//  Created by boWen on 2023/12/23.
//

#import "AY_VpUseCenterCell.h"

@interface AY_VpUseCenterCell ()

@property (nonatomic,strong) UIView * bg_View;//底部圆角
@property (strong,nonatomic) UILabel *topTitleLabel;
@property (strong,nonatomic) UILabel *downTitleLabel;
@property (strong,nonatomic) UILabel *downTitleLabel1;
@property (strong,nonatomic) UILabel *downTitleLabel2;
@property (strong,nonatomic) UILabel *topRightLabel;
@property (strong,nonatomic) UILabel *downRightLabel;


@end

@implementation AY_VpUseCenterCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubviewsWithUI];
    }
    return self;
}


- (void)addAllSubviewsWithUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = COLOR_Bg;
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(6) andAddSubView:self.contentView];
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];

    self.topTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#000002") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(16)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.topTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bg_View).offset(YNUM(14));
        make.left.equalTo(self.bg_View).offset(YNUM(14));
        make.height.offset(YNUM(24));
    }];
    
    self.downTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#909090") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:4 andRadius:0 andAddSubView:self.bg_View];
    [self.downTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topTitleLabel.mas_bottom).offset(YNUM(10));
        make.left.equalTo(self.bg_View).offset(YNUM(14));
        make.height.offset(YNUM(20));
    }];
    
    self.downTitleLabel1 = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#909090") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:4 andRadius:0 andAddSubView:self.bg_View];
    [self.downTitleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.downTitleLabel.mas_bottom).offset(YNUM(2));
        make.left.equalTo(self.bg_View).offset(YNUM(14));
        make.height.offset(YNUM(20));
    }];
    
    self.downTitleLabel2 = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#909090") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:4 andRadius:0 andAddSubView:self.bg_View];
    [self.downTitleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.downTitleLabel1.mas_bottom).offset(YNUM(2));
        make.left.equalTo(self.bg_View).offset(YNUM(14));
        make.height.offset(YNUM(20));
    }];
    
    self.topRightLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#000002") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(20)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.topRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bg_View).offset(YNUM(14));
        make.right.equalTo(self.bg_View).offset(YNUM(-14));
        make.height.offset(YNUM(30));
    }];
    
    self.downRightLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#818077") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:4 andRadius:0 andAddSubView:self.bg_View];
    [self.downRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.downTitleLabel.mas_top);
        make.right.equalTo(self.bg_View).offset(YNUM(-14));
        make.height.offset(YNUM(20));
    }];
    
}

- (void)setModel:(AssetRecordModel *)model {
    if ([model.recordType isEqual:@"2"]) {
        self.downTitleLabel2.hidden = YES;
        if ([model.recordDir isEqual:@"2"]) {
            self.topTitleLabel.text = @"系统扣除";
            self.downTitleLabel1.text = [NSString stringWithFormat:@"扣除天数：%@", kStringUtils(model.assetAmount)];
        }else {
            self.downTitleLabel1.text = [NSString stringWithFormat:@"%@天数：%@", [AYMMKV getStringForKey:GM], kStringUtils(model.assetAmount)];
            self.topTitleLabel.text = @"系统赠送";
        }
    }else if ([model.recordType isEqual:@"4"]) {
        self.downTitleLabel2.hidden = YES;
        self.topTitleLabel.text = @"系统兑换";
        self.downTitleLabel1.text = [NSString stringWithFormat:@"赠送天数：%@", kStringUtils(model.assetAmount)];
    }else {
        self.downTitleLabel2.hidden = NO;
        self.topTitleLabel.text = kStringUtils(model.assetTypeName);
        self.downTitleLabel1.text = [NSString stringWithFormat:@"%@天数：%@", [AYMMKV getStringForKey:GM], kStringUtils(model.assetAmount)];
    }
    
    if (!kStringIsEmpty(model.gmtCreate)) {
        NSString *time = [model.gmtCreate stringByReplacingOccurrencesOfString:@"T" withString:@" "];
        self.downTitleLabel.text = [NSString stringWithFormat:@"%@时间：%@", [AYMMKV getStringForKey:KT], time];
    }
    
    self.downTitleLabel2.text =  [NSString stringWithFormat:@"%@方式：%@", [AYMMKV getStringForKey:ZF], kStringUtils(model.paymentTypeName)];
        
    if (!kStringIsEmpty(model.orderAmount)) {
        self.topRightLabel.text = [NSString stringWithFormat:@"￥%@", kStringUtils(model.orderAmount)];
        NSString *labelText = self.topRightLabel.text;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
        NSRange rangeA = [labelText rangeOfString:@"￥"];
        [attributedString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:YNUM(12)] range:rangeA];
        self.topRightLabel.attributedText = attributedString;
    }
    
    if (!kStringIsEmpty(model.oriPrice)) {
        self.downRightLabel.text = [NSString stringWithFormat:@"￥%@", kStringUtils(model.oriPrice)];
        if (self.downRightLabel.text.length > 0) {
            NSString *labelText1 = self.downRightLabel.text;
            NSMutableAttributedString *attributedString1 = [[NSMutableAttributedString alloc] initWithString:labelText1];
            NSRange rangeB = [labelText1 rangeOfString:labelText1];
            [attributedString1 addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:rangeB];//删除线
            [attributedString1 addAttribute:NSStrikethroughColorAttributeName value:COLOR(@"#909090") range:rangeB];//删除线色
            self.downRightLabel.attributedText = attributedString1;
        }
    }
}


- (void)setFrame:(CGRect)frame {
    frame.origin.x += 16;
    frame.size.width -= 2 * 16;
    [super setFrame:frame];
}


@end
